﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Magento
{
    class Program
    {
        static void Info()
        {
            Console.WriteLine("use:");
            Console.WriteLine("magento.exe create:di <module_path>");
            Console.WriteLine("magento.exe create:event <module_path>");
            Console.WriteLine("magento.exe create:webapi <module_path>");
            Console.WriteLine("magento.exe create:routes <module_path> <route>");
            Console.WriteLine("magento.exe create:model <module_path> <model>");
            Console.WriteLine("magento.exe create:setup <module_path>");
        }

        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Program.Info();
                Console.ReadKey();
                return;
            }

            if (args[0] == "create:di")
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("Lack of necessary parameters");
                    return;
                }
                var gen = new Generation.DI();
                if (!gen.readAndCreate(args[1]))
                {
                }
                foreach (var message in gen.Messages())
                {
                    Console.WriteLine(message);
                }
            }
            else if (args[0] == "create:event")
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("Lack of necessary parameters");
                    Program.Info();
                    return;
                }
                var gen = new Generation.Event();
                if (!gen.readAndCreate(args[1]))
                {
                }
                foreach (var message in gen.Messages())
                {
                    Console.WriteLine(message);
                }
            }
            else if (args[0] == "create:routes")
            {
                if (args.Length < 3)
                {
                    Console.WriteLine("Lack of necessary parameters");
                    Program.Info();
                    return;
                }
                var gen = new Generation.Controller();
                if (!gen.readAndCreate(args[1], args[2]))
                {
                }
                foreach (var message in gen.Messages())
                {
                    Console.WriteLine(message);
                }
            }
            else if (args[0] == "create:webapi")
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("Lack of necessary parameters");
                    Program.Info();
                    return;
                }
                var gen = new Generation.WebAPI();
                if (!gen.readAndCreate(args[1]))
                {
                }
                foreach (var message in gen.Messages())
                {
                    Console.WriteLine(message);
                }
            }
            else if (args[0] == "create:model")
            {
                if (args.Length < 3)
                {
                    Console.WriteLine("Lack of necessary parameters");
                    Program.Info();
                    return;
                }
                var gen = new Generation.Model();
                if (!gen.readAndCreate(args[1], args[2]))
                {
                }
                foreach (var message in gen.Messages())
                {
                    Console.WriteLine(message);
                }
            }
            else
            {
                Console.WriteLine($"{args[0]} is not support");
            }

            //Console.ReadKey();
        }
    }
}
